package com.jt.controller;

import com.jt.pojo.Result;
import com.jt.pojo.Router;
import com.jt.service.RoleService;
import com.jt.service.RouterService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Arrays;
import java.util.List;
@Slf4j
@RestController
@RequestMapping("/router")
public class RouterController {
    @Autowired
    private RouterService routerService;
    @Autowired
    private RoleService roleService;

    /**
     * 查询菜单列表
     *
     * @return Result
     */
    @GetMapping("/selectRouterList")
    public Result selectRouterList() {
        List<Router> routerList = routerService.selectRouterList();
        return new Result().setCode(200).setData(routerList).setMasege("查询菜单列表");
    }

    /**
     * 分配权限
     *
     * @return Result
     */
    @GetMapping("/distributionRouter")
    public Result distributionRouter(String menuList,String RowRoleId ) {
        System.out.println(menuList);
        String[] menuString = menuList.split(",");
        List<String> MenuIdList = Arrays.asList(menuString);
         int count=routerService.distributionRouter(MenuIdList,RowRoleId);
         if (count>0){
             log.info("新增{}条菜单数据成功",count);
             return  new Result().setCode(200).setData(count).setMasege("分配成功");
         }else {
             return  new Result().setCode(500).setData(count).setMasege("分配失败");
         }

    }

}
